/*
Copyright (c) 2025 HeZongLun
NahidaProject is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan
PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

#include <algorithm>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <string>
#include <variant>
#include <vector>

namespace NahidaProject {
	class __declspec(dllexport) CommandLineParser {
	public:
		typedef std::variant<std::uint32_t*, bool*, std::string*> Value;
		struct Argument { std::vector<std::string> options_; Value value_; std::string desc_; };
		explicit CommandLineParser() = default;
		void Add(std::vector<std::string> const& opts, Value const& value, std::string const& desc);
		void PrintHelp(std::ostream& os = std::cout) const;
		void Parse(int argc, char* argv[]) const;

	private:
		uint32_t MaxOptionsLength(void) const {
			constexpr auto COMMA_LENGTH = 1U;
			constexpr auto SPACE_LENTH = 1U;
			uint32_t max_len = 0;

			for (auto const& arg : args_) {
				uint32_t len = 0;
				for (auto const& opt : arg.options_) {
					len += static_cast<uint32_t>(opt.size()) + COMMA_LENGTH + SPACE_LENTH;
				}
				max_len = std::max(max_len, len);
			}
			return max_len;
		}
	private:
		std::vector<Argument> args_;
	};
}